﻿using AutoMapper;
using Durian.API.Application.Commands.Process;
using IMES.Common.Domain.DurianModel;
using IMES.Common.Dtos;
using IMES.Common.Infrastructure;
using MediatR;

namespace Durian.API.Application.Commands.Assembly
{
    public class AssemblyUntilHandler : IRequestHandler<AssemblyUntilCommand, ResultT<Assemblies>>
    {
        private readonly IMapper mapper;
        private readonly ILogger<ProcessManagementCreateHandler> logger;
        private readonly IBaseRepositorys<ProcessManagement> processManagementRepository;
        private readonly IBaseRepositorys<SystemLogs> systemLogsRepository;
        private readonly IBaseRepositorys<Assemblies> assembliesRepository;
        private readonly IBaseRepositorys<OrderProducts> orderProductsRepository;

        public AssemblyUntilHandler(ILogger<ProcessManagementCreateHandler> logger, IMapper mapper, IBaseRepositorys<ProcessManagement> processManagementRepository, IBaseRepositorys<SystemLogs> systemLogsRepository, IBaseRepositorys<Assemblies> assembliesRepository, IBaseRepositorys<OrderProducts> orderProductsRepository)
        {
            this.logger = logger;
            this.mapper = mapper;
            this.processManagementRepository = processManagementRepository;
            this.systemLogsRepository = systemLogsRepository;
            this.assembliesRepository = assembliesRepository;
            this.orderProductsRepository = orderProductsRepository;
        }

        /// <summary>
        /// 反填装配工单信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ResultT<Assemblies>> Handle(AssemblyUntilCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = new ResultT<Assemblies>();

                //result.Item = assembliesRepository.GetAll().FirstOrDefault(c => c.AssemblyId == request.AssemblyId);
                logger.LogInformation("反填装配工单信息方法调用成功");
                return result;

            }
            catch (Exception ex)
            {
                logger.LogError("反填装配工单信息方法出错" + ex);
                throw;
            }
        }
    }
}
